package com.yc.jiushujie.jsj_order.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.jiushujie.entity.JsjBook;
import com.yc.jiushujie.entity.JsjCategory;
import com.yc.jiushujie.entity.JsjSearch;
import com.yc.jiushujie.entity.JsjUser;
import com.yc.jiushujie.jsj_order.mapper.JsjBookMapper;
import com.yc.jiushujie.jsj_order.mapper.JsjSearchMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 无罪
 * @since 2022-08-03
 */
@RestController
@RequestMapping("/jiushujie/jsjBook")
public class JsjBookController {
    @Resource
    private JsjBookMapper jsjBookMapper;

    @RequestMapping("queryHao")
    public List<JsjBook> queryNew(){
        IPage<JsjBook> page=new Page<>(1,50);
        page.orders().add(OrderItem.desc("up_time"));
        page=jsjBookMapper.selectPage(page,null);
        return page.getRecords();

    }
   @RequestMapping("findById")
   public JsjBook findById(@RequestParam int id){




        return  jsjBookMapper.selectById(id);

   }
//    @RequestMapping("queryUserByBid")
//
//    public List<JsjUser>queryUserByBid(@RequestParam int bid
//    ){
//
//        return jsjBookMapper.selectBYBid(bid);
//    }
    @RequestMapping("getowner")
    public JsjBook getowner(@RequestParam int id){
 id=jsjBookMapper.selectById(id).getId();


        return jsjBookMapper.selectBook(id);
    }
    @RequestMapping("queryAllBook")
    public  Page<JsjBook> queryAllBook(@RequestParam int page,@RequestParam int size){

        Page<JsjBook> ipage=new Page<>(page,size);
        ipage.orders().add(OrderItem.desc("id"));
        ipage.setRecords(jsjBookMapper.selectAllBook((page-1)*size,size));
        final  Map<String,Object>map=jsjBookMapper.selectCount();
        long total=Long.parseLong(map.get("cnt")+"");
        ipage.setTotal(total);
        return ipage;

        }

    }


